package com.xiong.word.model;

import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

public class XWPFParagraphModel {

    private XWPFParagraph xwpfParagraph;

    private Integer fontSize;

    private String fontFamily;

    public void replaceXWPFParagraph(String target,String replace){
        for (XWPFRun run : this.xwpfParagraph.getRuns()) {
            String text = run.getText(0);
            if (text != null && text.contains(target)) {
                text = text.replace(target, replace);
                run.setText(text, 0);
                if(fontFamily!=null){
                    run.setFontFamily(fontFamily);
                }
                if(fontSize!=null){
                    run.setFontFamily(fontFamily);
                }
            }
        }
    }

    public String getText(){
        String paragraphText = this.xwpfParagraph.getText();
        return paragraphText;
    }

    public void setFontSize(Integer fontSize){
        this.fontSize=fontSize;
    }

    public void setFontFamily(String fontFamily){
        this.fontFamily=fontFamily;
    }

    public XWPFParagraph getXwpfParagraph() {
        return xwpfParagraph;
    }

    public XWPFParagraphModel(XWPFParagraph xwpfParagraph) {
        this.xwpfParagraph = xwpfParagraph;
    }
}
